package com.molyfun.parents.activity.common.listactivity.factory;

import android.content.Context;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.molyfun.parents.MFPApplication;
import com.molyfun.parents.R;
import com.molyfun.parents.activity.common.listactivity.AbstractListFactory;
import com.molyfun.parents.activity.common.listactivity.IResponse;
import com.molyfun.parents.activity.common.listactivity.viewholder.RecommendProductHolder;
import com.molyfun.parents.im.model.ChatMessageEntity;
import com.molyfun.parents.rest.RestClient;
import com.molyfun.parents.rest.bean.CustomMsglistResponse;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:10/31/16.
 *
 * 咨询->推荐整理列表列表
 */
public class RecommendProductFactory extends AbstractListFactory<ChatMessageEntity> {

    private String mCustomPlanId;

    public RecommendProductFactory(String customplanid){
        mCustomPlanId = customplanid;
    }

    @Override
    public int getTitle() {
        return R.string.activity_title_mine_clearup;
    }

    @Override
    public void getDataList(int pageNum,final IResponse responseCallback) {

        Call<CustomMsglistResponse> call = MFPApplication.getInstance().getRestClient().getCustomplanMsgList(mCustomPlanId, "7", pageNum, RestClient.DEFAULT_PAGE_SIZE);
        call.enqueue(new Callback<CustomMsglistResponse>() {
            @Override
            public void onResponse(Call<CustomMsglistResponse> call, Response<CustomMsglistResponse> response) {
                if (response.body() != null && response.body().getData() != null ) {
                    responseCallback.onResponse(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<CustomMsglistResponse> call, Throwable t) {
            }
        });

    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(ViewGroup parent, int viewType) {
        return new RecommendProductHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.layout_recommend_product_cell, parent, false));
    }

    @Override
    public void bindViewHolder(final Context context, final ChatMessageEntity msgBean, RecyclerView.ViewHolder holder, final int position, FragmentManager fragmentManager, int totalSize) {
        RecommendProductHolder recommendProductHolder = (RecommendProductHolder)holder;
        recommendProductHolder.mRecommendProductCellView.initData(msgBean);
        if(position == (totalSize - 1)){
            recommendProductHolder.mRecommendProductCellView.initData(msgBean, true);
        }else{
            recommendProductHolder.mRecommendProductCellView.initData(msgBean);
        }
    }

    @Override
    public void deleteData(String id, int position) {

    }

}
